from flask_wtf import FlaskForm
from marshmallow import Schema, fields, pre_dump
from wtforms.fields.simple import TelField,StringField
from wtforms.validators import DataRequired,Length

class AccountSmsSchema(FlaskForm):
    phone = TelField('phone',validators=[DataRequired("手机号不能为空"),Length(max=11,min=11)])

class AccountSchema(FlaskForm):
    phone = TelField('phone',validators=[DataRequired("手机号不能为空"),Length(max=11,min=11)])
    guide_id = StringField("guide_id",validators=[DataRequired("导游id不能为空")])
    code = StringField("code",validators=[DataRequired("验证码不能为空")])
class PrductDescSchema(FlaskForm):
    product_id = StringField("product_id",validators=[DataRequired("product_id不能为空")])
class AccountResp(Schema):
    code = fields.String(dump_default="")
    @pre_dump
    def process_data(self,code:str, **kwargs):
        return {
            "code":code
        }
class AccountLoginSchema(Schema):
    access_token=fields.String(dump_default="")
    expires_in = fields.String(dump_default="")
    token_type = fields.String(dump_default="")
    scope  = fields.String(dump_default="")
    refresh_token = fields.String(dump_default="")
    @pre_dump
    def process_data(self,data:dict, **kwargs):
        print(data)
        print("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")
        return {
            "access_token":data.get("access_token"),
            "expires_in":data.get("expires_in"),
            "token_type":data.get("token_type"),
            "scope":data.get("scope"),
            "refresh_token":data.get("refresh_token")
        }